home *** CD-ROM | disk | FTP | other *** search
- Interface = function()
- {
- var sockets = this.sockets;
- var obj = this;
- var id = 0;
- var cable;
- for(var s in sockets)
- {
- var socket = sockets[s] = eval(sockets[s]);
- for(var s in sockets)
- {
- if(!sockets[s].connected_by)
- {
- sockets[s].to = "";
- sockets[s].cable_id = "";
- }
- }
- socket.watch("connected_to",function(id, oldVal, newVal)
- {
- this.to = newVal._name;
- return newVal;
- }
- );
- socket.connected_by = null;
- socket.connected_to = null;
- socket.onEnterFrame = function()
- {
- if(this.connected_by)
- {
- cable = this.connected_by;
- cable.onSwitchPlugs();
- cable.cable_mc.onEnterFrame = cable.cable_mc.render;
- cable.cable_mc.swapDepths(id);
- if(cable.s0 == this)
- {
- cable.s0 = Mouse;
- }
- delete this.connected_by;
- this = this.connected_to;
- delete this.connected_to;
- }
- else
- {
- var colors = [16250195,12188824,10010364,16551502];
- cable = new obj.Cable(obj,this,Mouse,colors[3],26);
- }
- };
- }
- };
- var p = Interface.prototype = new MovieClip();
- p.zSort = function(cable)
- {
- for(var c in this)
- {
- if(this[c] instanceof MovieClip)
- {
- var cable_mc = this[c];
- cable_mc.swapDepths(cable.cable_mc);
- }
- }
- };
- p.Cable = function(main_clip, s0, s1, col, size, id)
- {
- this.s0 = s0;
- this.s1 = s1;
- this.id = id;
- var darken = (col >> 16) * 0.6 << 16 | (col >> 8 & 255) * 0.6 << 8 | (col & 255) * 0.6;
- var nodesNum = 6;
- var ten = 5;
- var rel = 0.7;
- var gr = 4;
- var cable_mc = this.cable_mc = main_clip.createEmptyMovieClip("cable" + id,id);
- if(s0 !== Mouse)
- {
- var sx = s0._x;
- var sy = s0._y;
- }
- else
- {
- var sx = main_clip._parent.oppbossa1._x;
- var sy = main_clip._parent.oppbossa1._y;
- }
- if(s1 !== Mouse)
- {
- var tx = s1._x;
- var ty = s1._y;
- }
- else
- {
- var tx = main_clip._parent.oppbossa1._x;
- var ty = main_clip._parent.oppbossa1._y;
- }
- var nodes = [];
- var i = 0;
- while(i < nodesNum)
- {
- nodes[i] = {x:sx + (tx - sx) / (nodesNum + 1) * (i + 1),y:sy + (ty - sy) / (nodesNum + 1) * (i + 1)};
- i++;
- }
- var plug0 = cable_mc.attachMovie("plug","plug0",0,{_x:sx,_y:sy});
- plug0.nextFrame();
- var plug1 = cable_mc.attachMovie("plug","plug1",5);
- var obj = this;
- var d_mc;
- var s_mc;
- var o_mc;
- cable_mc.render = function()
- {
- d_mc.removeMovieClip();
- s_mc.removeMovieClip();
- o_mc.removeMovieClip();
- d_mc = this.createEmptyMovieClip("d_mc",2);
- s_mc = this.createEmptyMovieClip("s_mc",3);
- o_mc = this.createEmptyMovieClip("o_mc",4);
- var s0 = obj.s0;
- var s1 = obj.s1;
- if(s0 !== Mouse)
- {
- var sx = s0._x;
- var sy = s0._y;
- }
- else
- {
- var sx = main_clip._parent.oppbossa1._x;
- var sy = main_clip._parent.oppbossa1._y;
- }
- if(s1 !== Mouse)
- {
- var tx = s1._x;
- var ty = s1._y;
- }
- else
- {
- var tx = main_clip._parent.oppbossa1._x;
- var ty = main_clip._parent.oppbossa1._y;
- }
- for(var a in nodes)
- {
- var node = nodes[a];
- var a = Number(a);
- var prevnode = a <= 0 ? {x:sx,y:sy} : nodes[a - 1];
- var nextnode = a >= nodesNum - 1 ? {x:tx,y:ty} : nodes[a + 1];
- var vx = node.vx;
- var vy = node.vy;
- var a_x = node.x;
- var a_y = node.y;
- var p_x = prevnode.x;
- var p_y = prevnode.y;
- var n_x = nextnode.x;
- var n_y = nextnode.y;
- vx += (p_x - a_x) / ten;
- vy += (p_y - a_y) / ten;
- vx += (n_x - a_x) / ten;
- vy += (n_y - a_y) / ten;
- vy += gr;
- vx *= rel;
- vy *= rel;
- node.x = a_x + vx;
- node.y = a_y + vy;
- plug0._x = sx;
- plug0._y = sy;
- plug1._x = tx;
- plug1._y = ty;
- node.vx = vx;
- node.vy = vy;
- var nearVal = 0.005;
- if(s0 !== Mouse && s1 !== Mouse && vx < nearVal && vx > - nearVal && vy < nearVal && vy > - nearVal)
- {
- delete this.onEnterFrame;
- }
- }
- o_mc.lineStyle(size,darken,100);
- d_mc.lineStyle(size * 1.2,0,100);
- var val = 1.9;
- for(var a in nodes)
- {
- var node = nodes[a];
- var a = Number(a);
- var prevnode = a <= 0 ? {x:sx,y:sy} : nodes[a - 1];
- var a_x = node.x;
- var a_y = node.y;
- var p_x = prevnode.x;
- var p_y = prevnode.y;
- var last = a == nodesNum - 1;
- if(last)
- {
- var plug_rel_x = (a_x + p_x) / 2 - plug1._x;
- var plug_rel_y = (a_y + p_y) / 2 - plug1._y;
- }
- if((a_x + p_x) / 2 + val > a_x && (a_x + p_x) / 2 - val < a_x)
- {
- with(d_mc)
- {
- if(last)
- {
- moveTo(tx,ty);
- }
- lineTo((a_x + p_x) / 2,(a_y + p_y) / 2);
- }
- with(s_mc)
- {
- if(last)
- {
- moveTo(tx,ty);
- }
- lineTo((a_x + p_x) / 2,(a_y + p_y) / 2);
- }
- with(o_mc)
- {
- if(last)
- {
- moveTo(tx,ty);
- }
- lineTo((a_x + p_x) / 2,(a_y + p_y) / 2);
- }
- }
- else
- {
- with(d_mc)
- {
- if(last)
- {
- moveTo(tx,ty);
- }
- curveTo(a_x,a_y,(a_x + p_x) / 2,(a_y + p_y) / 2);
- }
- with(s_mc)
- {
- if(last)
- {
- moveTo(tx,ty);
- }
- curveTo(a_x,a_y,(a_x + p_x) / 2,(a_y + p_y) / 2);
- }
- with(o_mc)
- {
- if(last)
- {
- moveTo(tx,ty);
- }
- curveTo(a_x,a_y,(a_x + p_x) / 2,(a_y + p_y) / 2);
- }
- }
- }
- plug1.mask._rotation = Math.atan2(plug_rel_y,plug_rel_x) * 180 / 3.14;
- d_mc.curveTo((sx + a_x) / 2,(sy + a_y) / 2,sx,sy);
- s_mc.curveTo((sx + a_x) / 2,(sy + a_y) / 2,sx,sy);
- o_mc.curveTo((sx + a_x) / 2,(sy + a_y) / 2,sx,sy);
- };
- this.remove = function()
- {
- delete cable_mc.onEnterFrame;
- d_mc.removeMovieClip();
- s_mc.removeMovieClip();
- o_mc.removeMovieClip();
- plug0.removeMovieClip();
- plug1.removeMovieClip();
- cable_mc.removeMovieClip();
- };
- this.onConnecting = function()
- {
- plug1.nextFrame();
- plug1.swapDepths(1);
- };
- this.onSwitchPlugs = function()
- {
- plug0.swapDepths(5);
- plug0.prevFrame();
- plug1.swapDepths(0);
- var tp = plug0;
- plug0 = plug1;
- plug1 = tp;
- };
- cable_mc.onEnterFrame = cable_mc.render;
- cable_mc.onEnterFrame();
- };
- Object.registerClass("cable_interface",Interface);
-